121A - Lucky Sum - CodeForces Solution


implementation *1100

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(a, b, c) for (int(a) = (b); a < (c); a++)
#define nl '\n'
#define MAXN   10000
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
const ll int N = 1e9;
/*⠀⠀⠀⠀⠀⠀⠀⠀

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⣠⣴⣶⣶⣶⣶⣿⣿⣶⣶⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣄⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⠟⠙⣿⣿⠈⣿⣿⣿⠟⠟⣿⣿⣿⣿⣿⣯⣇⣿⣿⣿⡏⣀⣩⡿⢿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⠋⣫⢁⣄⣿⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⣘⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣶⣿⣿⣿⡿⠿⠿⢿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠘⢿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⠋⠉⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠛⠛⠛⠙⠻⠛⠉⠉⠉⠉⠙⠛⢿⣿⣿⣇⣀⣠⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀   ⠀⠉⢿⣿⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀   ⠀⠀⠀⠀⢸⣯⠉⢿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀   ⠀⠀⠈⢿⣦⡀⠹⢿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀    ⠀⠈⢻⡄⢨⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⢃⣠⣶⣿⣿⣶⣤⣤⣄⣀⠀⠀⠀⠀⠀⣀⣤⣴⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⢤⣽⣓⠻⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡇⣿⡿⠁⢀⣀⣈⣉⣻⣿⡿⠁⠀⠀⠀⢸⣿⣿⠟⡩⠿⣶⣤⣉⡙⠿⣿⡄⠀⠀⠀⠀⠀⢸⣿⣿⡃⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡇⠉⠀⣴⣶⣿⣿⠻⣿⣿⣿⡆⠀⠀⠀⠘⣿⣿⣾⣷⣿⣿⣿⣿⣿⣶⣍⠁⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡇⠀⠀⠏⠉⠉⠁⢠⣾⣿⠟⠀⠀⠀⠀⠀⠘⢿⣿⣿⣌⠭⢬⣧⡀⠉⠛⠃⠀⠀⠀⠀⠀⠈⣿⣿⣿⣿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⠃⠀⠀⠀⠐⠒⢚⡭⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠻⠿⠶⠾⣟⡉⠀⠀⠀⠀⠀⠀⠀⠀⠸⠟⣣⢷⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡀⠀⠀⠀⠀⠀⠉⠀⠀⢀⡆⠀⠀⠀⠀⠀⠀⠀⣼⣦⠀⠀⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡉⠀⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⣴⡟⢀⠀⢀⣀⠀⠀⠀⠀⢻⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡆⢻⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⢀⣼⠟⠶⠿⠆⣼⣿⡟⠰⠾⢷⡾⠿⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⡇⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⢿⡇⠀⠀⠀⠀⢀⡾⠉⠀⣀⣀⣀⣭⣿⢿⣿⠷⣶⣷⣦⣜⣿⠿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠟⠉⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀⠰⠇⣠⣶⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⢿⣿⣿⣤⠙⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣇⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⢸⣷⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡀⢦⣤⣾⣿⣿⣿⣿⣿⠿⠛⠛⠛⠛⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡶⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣇⠀⠙⠛⠻⣿⠟⠋⠀⠀⢀⣠⣾⣿⣿⣿⣿⠛⠛⠛⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣄⠀⠀⠀⠁⠀⠀⠀⠀⠘⠿⠿⠿⠿⠿⠿⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⡳⣄⢀⠀⠀⠀⠀⠀⠀⢀⣤⣤⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣯⣻⢿⣷⣦⣤⣤⣶⣿⣿⣿⣿⣿⣿⣦⠀⢀⣀⣠⠴⠄⠀⠀⠀⠀⠀⣾⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⡳⣯⡻⠛⠛⠿⠿⠿⣿⣿⣿⣿⣿⠿⠋⠉⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡹⣦⠀⠀⠀⠀⠈⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣷⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣀⣀⣤⣴⡾⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⡳⣤⡀⠀⠀⢻⣿⣿⣿⡆⠀⠀⠀⠀⠀⢀⣤⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣤⣀⡀⠀⠀⠀⠀
⠀⢀⣠⣴⣶⣿⣿⣿⡿⢟⣳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣦⣍⠲⢤⡀⠈⠙⢿⣇⠀⠀⠀⣀⡴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡾⣿⣿⣿⣿⣿⣷⣦⣀⠀
⢿⣿⣿⣿⡿⢟⣻⣥⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣵⣌⠻⣿⣿⣿⣿⣿⣿⣿⣦⡙⠳⣤⣼⣧⣀⡤⢚⣵⣾⣿⣿⣿⣿⣿⢏⡛⠿⣿⣿⣿⣿⣿⣿⣷⣶⣿⣽⣿⣿⣿⣿⣿⠇
⠀⠙⠛⠻⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢏⣾⡿⢿⣷⡽⣿⣿⣿⣿⣿⣿⣿⣿⣷⢲⣤⣽⣥⣾⣿⣿⣿⣿⣿⣿⣿⡟⢸⡿⠳⣌⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀
⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⡁⢀⣼⠀⣿⡟⢿⣿⣿⣿⣿⣿⣿⣿⡀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿⡀⢀⡙⢻⡄⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⠉⠛⠻⠿⢿⣿⣿⣿⣿⣿⣿⣮⢳⣾⣧⣾⣿⣿⣎⢿⣿⣿⣿⣿⣿⡿⠁⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⣿⣿⣾⣷⣿⠇⣿⣿⣿⣿⡿⠛⠉⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⢿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⣦⡻⣿⣿⣿⠟⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿⣿⠀⣿⣿⡟⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣽⠟⠁⢀⣾⣿⣿⡄⢠⣿⣿⣿⣿⣿⣿⣿⠃⣼⣿⣿⣿⣿⡇⠀⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 */
/*
vector<ll> getFactorization(ll x)
{
    vector<ll> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
int computeXOR(int n)
{

    // If n is a multiple of 4
    if (n % 4 == 0)
        return n;

    // If n%4 gives remainder 1
    if (n % 4 == 1)
        return 1;

    // If n%4 gives remainder 2
    if (n % 4 == 2)
        return n + 1;

    // If n%4 gives remainder 3
    return 0;
}

ll length(ll z)
{
    ll a=0;
    while(z)
    {
        a++;
        z/=10;
    }
    return a;
}


int prime(int z)
{
    for (int i = 2; i*i<=z;i++)
    {
        if(z%i==0)
        {
            return 1;
        }
    }
    return 0;
}


ll fastpow(ll a,ll b,ll mod)
{
    if(b==0)
    {
        return 1;
    }
    ll res= fastpow(a,b/2,mod);
    res=(res*res)%mod;
    if(b%2==1)
    {
        res=(res*a)%mod;
    }
    return res;
}



int setBitNumber(int n)
{
    if (n == 0)
        return 0;

    int msb = 0;
    n = n / 2;
    while (n != 0) {
        n = n / 2;
        msb++;
    }

    return (1 << msb);
}
        if (spf[i] == i)
        {

            for (int j=i*i; j<N; j+=i)


                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
long long nextpowerof2(ll p)
{
    if(!(p&(p-1)))
    {
        return p;
    }
    return 0x8000000000000000>>(__builtin_clzll(p)-1);
}
*/

bool prime[10000001];

void Sieve(){
    memset(prime, true, sizeof(prime));

    for (int p=2;p*p<=10000000;p++){
        if (prime[p]){
            for (int i=p*p;i<=10000000;i+=p){
                prime[i]=false;
            }
        }
    }
}

bool sortbysec(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

bool cmp(pair<int,int>&a, pair<int, int>&b)
{
    if(a.first>b.first)
    {
        return true;
    }
    if(a.first==b.first && a.second< b.second)
    {
        return true;
    }
    return false;
}
vector<ll>lucky;

void check(ll l)
{
    if(l>1e10)
    {
        return ;
    }
    lucky.push_back(l);
    check((l*10)+4);
    check((l*10)+7);
}

int main() {
    check(0);
    lucky.erase(lucky.begin());
    fast;
    ll x,y;
    cin>>x>>y;

    sort(lucky.begin(),lucky.end());
    ll o= lower_bound(lucky.begin(),lucky.end(),x)-lucky.begin();
    ll ans=0;
    for(ll i=x;i<=y;i++)
    {
         while(i>lucky[o])
         {
             o++;
         }
         ans+=lucky[o];
    }
    cout<<ans<<endl;
}


Comments

Submit
0 Comments
More Questions

123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum